package mapper;

import com.sqsf.javabean.Role;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface RoleMapper {
    @Select("select r.* from role r inner join user_role ur on ur.rid=r.rid where ur.uid=#{uid}")
    Role selectByUid(int uid);

    @Select("select * from role")
    @Results(id = "r_p",value = {
            @Result(id = true,column = "rid",property = "rid"),
            @Result(property = "permissionList",column = "rid",many = @Many(
                    select="mapper.PermissionMapper.selectByRid",
                    fetchType = FetchType.LAZY
            ))
    })
    List<Role> selectRole_Permission();
}
